\documentclass[12pt]{article}
\usepackage{times}
\usepackage{graphicx}
\usepackage{sidecap}
\usepackage{wrapfig}
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\baselinestretch}{1.2}
\newenvironment{mylisting}
{\begin{list}{}{\setlength{\leftmargin}{1em}}\item\scriptsize\bfseries}
{\end{list}}

% This file is Open Content

\begin{document}
	\textbf{{\Huge Objective C NexT in X-windows}}
{\center{Dec 30, 2011, 
	Johan Ceuppens, Theo D'Hondt - Vrije Universiteit Brussel}}
\\
{\large{\textbf{\center Abstract}}}
\\
\\
\section{\large Introduction}

X-windows provides widget sets since 1986, e.g. Xext, Xaw, Xaw3D.
To configure a NeXT widget set as on (relatively) old Apple II which
was the basis for NexT itself, we need a GUI which can be modified
using boxes for widget placement (e.g. GTK+.)

Interface Builder was the graphical configurator for NeXT and provides
a drag and drop meta system.

This paper contains code to program NeXT widgets in X-windows using objC.
The code uses a XImage display of the widget, a main class pattern
and Cocoa or Carbon framework.

\section{\large objC code for NeXT }

 

\begin{mylisting}
\begin{verbatim}
	
/*
 Copyright (C) Johan Ceuppens 2011-2012

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 2 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
@interface NLScreen
{
	int x,y,w,h,bpp;
	unsigned int *pixels;
}
- (id) init;

- (void)NLsetX:(int)x1 Y:(int)y1 W:(int)w1 H:(int)h1;

- (void) NLPutPixelX:(int)x1 Y:(int)y1 Color:(unsigned int)color;
@end

/*
 Copyright (C) Johan Ceuppens 2011-2012

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 2 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#include "NLScreen.h"

@implementation NLScreen
- (id) init
{
//	self = [super init];
	if (self)
	{
	}
}

- (void) NLsetX:(int)x1 Y:(int)y1 W:(int)w1 H:(int)h1
{
	x = x1;
	y = y1;
	w = w1;
	h = h1;
}

- (void) NLPutPixelX:(int)x1 Y:(int)y1 Color:(unsigned int)color
{
	pixels[y1*w+x1] = color;
}

@end	

/*
 Copyright (C) Johan Ceuppens 2011

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 2 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef NLIMAGE_H
#define NLIMAGE_H

#include<X11/Xlib.h>
#include<X11/xpm.h>

#include "NLImageBase.h"

@interface NLImage//FIXME1 super==NLImageBase
{
  XImage *image;
}

-(id)  init:(Display **)dpy;
- (id) init:(Display **)dpy withXpm:(char *)xpm Width: (int)w Height:(int)h bpp:(int)bpp;
-(int) drawOnDisplay:(Display **)dpy Window:(Window *)w X:(int) xx Y:(int) yy;
-(int) putPixelX:(int) xx Y:(int) yy Color:(unsigned long) value;

@end
#endif
/*
 Copyright (C) Johan Ceuppens 2011

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 2 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#include "NLImage.h"

@implementation NLImage

- (id) init:(Display **)dpy
{
	int depth = DefaultDepth(*dpy, DefaultScreen(*dpy));
  	Visual *visual = DefaultVisual(*dpy, DefaultScreen(*dpy));
//	image = XCreateImage(*dpy, visual, depth, XYPixmap,0,(char *)post_xpm,24,24,8,1); 
}

- (id) init:(Display **)dpy withXpm:(char *)xpm Width: (int)w Height:(int)h bpp:(int)bpp
{
	int depth = DefaultDepth(*dpy, DefaultScreen(*dpy));
  	Visual *visual = DefaultVisual(*dpy, DefaultScreen(*dpy));
	image = XCreateImage(*dpy, visual, depth, XYPixmap,0,(char *)xpm,w,h,bpp,1); 
}

- (int) drawOnDisplay:(Display **)dpy Window:(Window *)w X:(int) destxx Y:(int) destyy
{
  #define NIL (0)
  GC gc = XCreateGC(*dpy, *w, 0, NIL);
  XPutImage(*dpy, *w, gc, image, 0,0,destxx,destyy,500,500);

  return 0;
}

- (int) putPixelX:(int) xx Y:(int) yy Color:(unsigned long) value
{
	XPutPixel(image, xx,yy,value);

}
@end

/*
 Copyright (C) Johan Ceuppens 2011-2012

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 2 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
// Written by Ch. Tronche (http://tronche.lri.fr:8000/)
// Copyright by the author. This is unmaintained, no-warranty free software. 
// Please use freely. It is appreciated (but by no means mandatory) to
// acknowledge the author's contribution. Thank you.
// Started on Thu Jun 26 23:29:03 1997

//
// Xlib tutorial: 2nd program
// Make a window appear on the screen and draw a line inside.
// If you don't understand this program, go to
// http://tronche.lri.fr:8000/gui/x/xlib-tutorial/2nd-program-anatomy.html
//
#import <objc/objc.h>
#import <objc/Object.h>
#include "NLScreen.h"
#include <X11/Xlib.h> // Every Xlib program must include this
#include <assert.h>   // I include this to test return values the lazy way
#include <unistd.h>   // So we got the profile for 10 seconds
#include <X11/Xlib.h>
#include <X11/xpm.h>


#define NIL (void *)0

@interface NLMain
{
 Display *dpy;
}
-(id) init;
- (void) print_usage;
@end

@implementation NLMain
-(id) init
{
	 NLScreen *screen = [NLScreen init];
}

- (void) run 
{
@try {//main code block
	
	
	dpy = XOpenDisplay(NIL);
	assert(dpy);
	//FIXME use a bridge

	int blackColor = BlackPixel(dpy, DefaultScreen(dpy));
 	int whiteColor = WhitePixel(dpy, DefaultScreen(dpy));
	
	Window w, titlebarw;
	XSetWindowAttributes attrib_create;
	unsigned long create_mask = CWBackPixmap | CWBorderPixel |
                              CWOverrideRedirect | CWEventMask | CWBackingPixel;

	attrib_create.background_pixmap = None;
	attrib_create.override_redirect = True;
	attrib_create.event_mask = ButtonPressMask | ButtonReleaseMask |
                             ButtonMotionMask | EnterWindowMask;
	XSizeHints theSizeHints;
        XWMHints theWMHints;

	theWMHints.initial_state = NormalState;
        theWMHints.flags = StateHint;

        theSizeHints.flags = PPosition | PSize;
        theSizeHints.x = 0;//x;
        theSizeHints.y = 0;//y;
        theSizeHints.width = 800;//width;
        theSizeHints.height = 600;//height;

  	Window root_window = RootWindow(dpy, DefaultScreen(dpy));
  	int depth = DefaultDepth(dpy, DefaultScreen(dpy));
  	Visual *visual = DefaultVisual(dpy, DefaultScreen(dpy));
	w = XCreateWindow(dpy, root_window, 40, 40, 
			800, 600,
			1, depth, InputOutput,
			visual, create_mask,
			&attrib_create);
        //XSetWMHints(dpy,w,&theWMHints);
        //XSetNormalHints(dpy,w,&theSizeHints);
  	titlebarw = XCreateWindow(dpy, root_window, 40, 20, 
				800, 20,
				1, depth, InputOutput,
				visual, create_mask,
				&attrib_create);
	XReparentWindow(dpy, titlebarw, w, 0, 0);
	///////RayMantaWindow raywindow(&dpy,w,titlebarw);

	XSelectInput(dpy, w, StructureNotifyMask);

	XMapWindow(dpy, titlebarw);
	XMapWindow(dpy, w);

	GC gc = XCreateGC(dpy, w, 0, NIL);

	XSetForeground(dpy, gc, whiteColor);
 
	XEvent e;
	int k;
  	for (k = 0; k < 100000; k++) {
	//NOTE: draw() is inside eventloop processor
	XFillRectangle(dpy, titlebarw, gc,0,0,800,20);
	XFillRectangle(dpy, w, gc,0,0,800,600);
	////////xmantaray.eventloop(xmantaray/*,&dpy*/,&e);
	XFlush(dpy);
  }
  sleep(20);

} @catch (id e) {

	printf("main excepted");

}
}

- (void) print_usage
{
	printf("\tnextlisp [OPTIONS]\n");
}

@end 


main()
{
	[ [ NLMain init ] run];

}


\end{verbatim}
\end{mylisting}
\section{\large Conclusion}
yet to be filled in.
\bibliographystyle{plain}
\bibliography{refs} % refs.bib

\end{document}

